﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using UIShare;

namespace EFong.View.TouringParty
{
    public partial class Frm_TourItemType : BasicForm
    {
        private Proxy.MasterServiceProxy _masterProxy { get { return Proxy.MasterServiceProxy.GetInstance(); } }

        public Frm_TourItemType()
        {
            InitializeComponent();

            this.gv_Users.OptionsView.NewItemRowPosition = NewItemRowPosition.Top;
        }

        protected override void InitFields()
        {
        }

        protected override void Events()
        {
            this.gv_Users.InitNewRow += (s, e) =>
                {
                    Contract.User newUser = this.gv_Users.GetRow(e.RowHandle) as Contract.User;

                    if (newUser != null)
                        newUser.Effective = true;
                };
        }

        protected override void LoadDatas()
        {
            this.bds_User.DataSource = _masterProxy.GetTourItemTypeList().ReturnValue;
        }

        private void bar_Main_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            switch (e.Item.Name)
            {
                case "bbt_Save":
                    this.save();
                    break;
                case "bbt_Close":
                    this.Close();
                    break;
                default:
                    break;
            }
        }

        private void save()
        {
            UIOperManager.SaveData(
                    () =>
                        {
                            this.gv_Users.PostEditor();

                            return _masterProxy.UpdateTourItemTypeList(this.bds_User.DataSource as List<Contract.TourItemType>).IsSuccess;
                        },
                    MsgResource.Save_Complete
                );
        }
    }
}
